﻿using ctolua.Models.Enum;

namespace ctolua.Models.UI.control
{
    public class MCItem : Mui
    {
        public override EUi type { get => EUi.物品; set => base.type = EUi.物品; }


        private Item? _item;
        /// <summary>
        /// 绑定物品对象到物品组件
        /// </summary>
        public Item? item
        {
            get => _item;
            set
            {
                if (value != null)
                {
                    game_api.set_item_on_ui_comp(this.role, value, this.id);
                }

                _item = value;
            }
        }

        


        private EKeyboardKey? _key;
        /// <summary>
        /// 设置按钮快捷键
        /// </summary>
        public EKeyboardKey? key
        {
            get => _key;
            set
            {
                if (value != null)
                {
                    game_api.set_btn_short_cut(this.role, this.id, (int)value);
                }

                _key = value;
            }
        }
        private int? _key2;
        /// <summary>
        /// 设置按钮快捷键 
        /// </summary>
        public int? key2
        {
            get => _key2;
            set
            {
                if (value != null)
                {
                    game_api.set_btn_short_cut(this.role, this.id, value);
                }

                _key2 = value;
            }
        }
        private EKeyboardKey? _smart_cast_key;
        /// <summary>
        /// 设置智能施法快捷键
        /// </summary>
        public EKeyboardKey? smart_cast_key
        {
            get => _smart_cast_key;
            set
            {
                if (value != null)
                {
                    game_api.set_skill_btn_smart_cast_key(this.role, this.id, (int)value);
                }

                _smart_cast_key = value;
            }
        }


        public MCItem()
        {
            
        }

        public MCItem(string id) : base(id)
        {
            getChild();
        }

        public MCItem(MCItem u) : base(u)
        {
            this.item = u.item;
            this.key = u.key;
            this.smart_cast_key = u.smart_cast_key;
            getChild();


        }
        public MCImage 背景 { get; set; }
        public MCImage 图标 { get; set; }
        public MCLabel 堆叠层数 { get; set; }
        public MCLabel 充能层数 { get; set; }
        public MCProgress cd { get; set; }
        public MCImage 禁用 { get; set; }

        /// <summary>
        /// 获得子控件
        /// </summary>
        public void getChild()
        {
           
            this.背景 = this.get_comp_by_path<MCImage>("equip_bg_img");
            this.背景.image_id = 133822;

            this.图标 = this.get_comp_by_path<MCImage>("equip_icon_img");

            this.堆叠层数 = this.get_comp_by_path<MCLabel>("equip_stack_label");
            this.堆叠层数.show = false;

            this.充能层数 = this.get_comp_by_path<MCLabel>("equip_charge_label");
            this.充能层数.show = false;

            this.cd = this.get_comp_by_path<MCProgress>("equip_cd_progress");
            this.cd.current_value = new bar()
            {
                time = 0,
                value = 0,
            };

            this.禁用 = this.get_comp_by_path<MCImage>("equip_disabled_img");
            this.禁用.image_id = 131921;
        }


        /// <summary>
        /// 设置物品组件绑定单位
        /// </summary>
        /// <param name="u">单位</param>
        /// <param name="type">插槽类型</param>
        /// <param name="slot_index">插槽位置</param>
        public void set_ui_unit_slot(Unit u, ESlotType type, int slot_index)
        {
            game_api.set_ui_comp_unit_slot(this.role, this.id, u, (int)type, slot_index);
        }


    }
}
